<!-- 本页样式 -->
<style scoped lang="scss">
.del-dialog-cnt {
  font-size: 16px;
  text-align: center;
}
</style>
<style lang="scss">
.applybatch_list {
  .transform {
    .el-icon-sort {
      transform: rotate(90deg) !important;
    }
  }
}
.applybatch-list-popover {
  // background: rgb(243, 243, 243) !important;
  // border-color: #c6e2ff !important;
  // background-color: #ecf5ff;
  .popper__arrow::after {
    // border-left-color: rgb(243, 243, 243) !important;
    border-left-color: #409eff !important;
    // border-left-color: #c6e2ff !important;
    // background-color: #ecf5ff;
  }
}
.delconfirm {
  border: solid 1px #db2828;
  line-height: 30px;
  border-radius: 2px;
  background-color: #ffe8e6;
  color: #db2828;
  margin: 1em 0em;
  padding: 5px 10px;
}
.delconfirminput {
  .el-input__inner {
    background: #fff0f0;
    border-color: #dbb1b1;
    color: #d95c5c;
    border-radius: 2px;
  }
}
.deldialog {
  .el-dialog__body {
    padding: 0px 20px 10px;
  }
}
.el-tooltip__popper {
  max-width: 30%;
}
.tabcolumn_left,
.tabcolumn_left > .cell {
  width: 200px !important;
}
.el-table .cell {
  white-space: nowrap !important;
}
</style>
<!-- 页面布局-->
<template>
  <div class="table applybatch_list">
    <!-- 主体区 -->
    <div class="container">
      <!-- 数据列表 -->
      <div class="grid-data-box">
        <el-table
          :height="$util.setDiaTableHeight()"
          :data="tableData"
          border
          stripe
          :cell-class-name="changeColumnClass"
          :header-cell-style="{ background: '#F3F3F3', color: '#606266' }"
          show-overflow-tooltip
          style="width: 100%"
          ref="multipleTable"
        >
          <el-table-column
            type="index"
            label="序号"
            width="50"
            show-overflow-tooltip
          ></el-table-column>
          <template v-for="(column, i) in columnData">
            <el-table-column
              :prop="column.columnCode"
              :key="i"
              sortable
              v-if="
                column.columnCode == 'fileName' &&
                (column.visiable == '1' || column.visiable == 1)
              "
              :label="column.columnName"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <div
                  class="fxrow fxcc"
                  style="display: flex; justify-content: space-between"
                >
                  <el-popover placement="right" width="330" trigger="hover">
                    <span>{{ scope.row.fileName }}</span>
                    <span
                      slot="reference"
                      style=""
                      >{{ scope.row.fileName }}</span
                    >
                  </el-popover>
                  <a :href="scope.row.fileUrl" :download="scope.row.fileName">
                    <i
                      class="el-icon-download"
                      style="cursor: pointer; font-size: 14px"
                    ></i>
                  </a>
                </div>
              </template>
            </el-table-column>
            <el-table-column
              :prop="column.columnCode"
              :key="i"
              sortable
              v-else-if="
                column.columnCode !== 'fileName' &&
                (column.visiable == '1' || column.visiable == 1)
              "
              :label="column.columnName"
              show-overflow-tooltip
            >
            </el-table-column>
          </template>
        </el-table>
      </div>
      <!-- 数据列表END -->
      <!-- 翻页导航条 -->
      <div class="navigate-box">
        <div class="pagination">
          <el-pagination
            background
            @current-change="handleCurrentChange"
            :total="parampters.totalCount"
            @size-change="handleSizeChange"
            :current-page.sync="parampters.pageIndex"
            :page-sizes="[20, 50, 100, 200]"
            :page-size="parampters.pageRows"
            layout="total, sizes, prev, pager, next"
          ></el-pagination>
        </div>
      </div>
      <!-- 翻页导航条END -->
    </div>
  </div>
</template>
<script>
import taskdetail from "./task_upd";
import tasksubupd from "./tasksub_upd";
import tasksubdetail from "./tasksub_list";

export default {
  data() {
    return {
      // 筛选条件
      parampters: {
        //查询参数
        loginsid: "", //登录会话SID
        pageRows: 20, //每页行数
        pageIndex: 1, //当前页
        pageCount: 0, //总页数
        totalCount: 0, //总记录数
        produceName: "", //申请年份
        ispCode: "",
        vopCode: "",
        produceCode: "",
        status: "",
      },
      ispList: [],
      vopList: [],
      // 查询出的表格数据
      tableLoading: true,
      columnData: [],
      tableData: [],
      //confirm提示信息弹框
      confirmBox: null,
      //所选记录id
      selectedId: "",
      //事物类型
      actType: "list",
      //字典集
      dicts: {},
      dialogVisible: false,
      dialog_time: 5,
      dialogTimer: null,
      delDialogVisible: false,
      delApplyBatchNo: "",
      confirmDelApplyBatchNo: "",
      showDeltips: false,
      allStatusButton: [],
    };
  },
  props: {
    sourceData: {
      required: true,
    },
  },
  // 进入页面加载数据
  mounted() {
    this.handleInitLoad();
  },
  methods: {
    /**
     * 组件初始化加载
     */
    handleInitLoad() {
      this.produceId = this.sourceData.seleid;
      this.loadColumnData();
      this.searchLoad();
    },

    /**
     * 初始加载字典选项
     */
    initSelectOptoins() {
      this.loadSelectOptoins("dictionary", { type: "produceStatus" });
      // this.loadSelectOptoins("cardapply", null);
      // this.loadSelectOptoins("dataformatNo", null);
    },

    /**
     * 通用定义:下拉字典
     *  @augments dictKind 字典类型
     */
    loadSelectOptoins(dictKind, params) {
      let url = "/herp/dictionary/";
      this.$axios
        .get(url, {
          params: params,
          headers: {
            operator: this.$util.getLoginer().userid,
            withCredentials: true,
          },
        })
        .then((res) => {
          let data = res.data;
          if (data.success) {
            this.$set(this.dicts, dictKind, data.data.list);
          } else {
            this.$error(data.message);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    changeColumnClass(data) {
      if (data.columnIndex == 2) {
        data.column.width = 160;
        return "tabcolumn_left";
      }
    },

    /**
     * @augments  row 行所在的数据
     * 表格数据列 内容字典转换
     */
    formatter(row, column) {
      if (column.property == "dataformatNo") {
        return this.$dicts.transDict(
          this.dicts.dataformatNo,
          "code",
          "name",
          row.dataformatNo
        );
      } else if (column.property == "status") {
        return this.$dicts.transDict(
          this.dicts.cardapply,
          "code",
          "name",
          row.status
        );
      } else if (column.property == "timestamp") {
        if (
          row.timestamp == undefined ||
          row.timestamp == null ||
          row.timestamp == ""
        ) {
          return "";
        } else {
          let now = new Date(Number(row.timestamp));
          let y = now.getFullYear();
          let m = now.getMonth() + 1;
          let d = now.getDate();
          return (
            y +
            "-" +
            (m < 10 ? "0" + m : m) +
            "-" +
            (d < 10 ? "0" + d : d) +
            " " +
            now.toTimeString().substr(0, 8)
          );
        }
      }
    },

    /**
     * @augments val 页码
     * 切换页码操作
     */
    handleCurrentChange(val) {
      this.parampters.pageIndex = val;
      // 重新获取当前页码的数据
      this.searchLoad();
    },

    /**
     * @augments val 每页显示条数
     * 每页显示条数修改
     */
    handleSizeChange(val) {
      // 修改每页显示条数
      this.parampters.pageRows = val;
      // 重新获取数据
      this.searchLoad();
    },
    /**
     * 条件筛选查询,加载数据
     */
    searchLoad() {
      // this.parampters = this.$util.trimObjStr(this.parampters);
      // this.parampters.loginsid = this.$util.getLoginer().sessionId;
      this.tableLoading = true;
      this.$axios
        .get(`/herp/produce/${this.produceId}/producerst/`, {
          params: null,
          headers: {
            operator: this.$util.getLoginer().userid,
            withCredentials: true,
          },
        })
        .then((res) => {
          let data = res.data;
          if (data.success) {
            this.tableData = data.data.list;
            this.tableLoading = false;
            this.parampters.pageIndex =
              data.data.pageNum != undefined ? parseInt(data.data.pageNum) : 0;
            this.parampters.pageCount =
              data.data.totalPage != undefined
                ? parseInt(data.data.totalPage)
                : 0;
            this.parampters.totalCount =
              data.data.count != undefined ? parseInt(data.data.count) : 0;
          } else {
            this.tableLoading = false;
            this.$error(data.message);
          }
        })
        .catch((err) => {
          this.tableLoading = false;
          console.log(err);
        });
    },

    /**
     * 获取右侧可点击按钮
     */
    getRightButton(row) {
      // let rightbtn = this.allStatusButton[row.status];
      // this.rightButton = this.allStatusButton;
      // console.log(this.rightButton)
      // this.allRightButton.forEach(button => {
      //   rightbtn.forEach(item => {
      //     if (button.tag == item.tag) {
      //       this.rightButton.push(button);
      //     }
      //   });
      // });
    },

    /**
     * 点击右侧按钮
     */
    handleClickMore(row, method) {
      this[method](row);
    },

    /**
     * 校验当前是否有未通过的制卡申请单
     */
    preApply(flag) {
      // this.$axios
      //   .get("/herp/cardApplyBatchs/unConfirmed/", {
      //     headers: {
      //       operator: this.$util.getLoginer().userid,
      //       withCredentials: true
      //     }
      //   })
      //   .then(res => {
      //     let data = res.data;
      //     if (data.success) {
      switch (flag) {
        case "file":
          this.toFileApply();
          return;
        case "batch":
          this.toBatchApply();
          return;
        case "white":
          this.toApply();
          return;
      }
      //   } else {
      //     this.$error(data.message);
      //   }
      // })
      // .catch(err => {
      //   console.log(err);
      // });
    },

    /**
     * 制卡文件导入
     */
    toFileApply() {
      //页面参数
      var pageParam = {
        loginInfo: this.$util.getLoginer(),
        actType: "add",
        seleid: "-1",
      };
      let commDialog = this.$dialog.commDialog(
        "制卡文件导入",
        fileapply,
        pageParam,
        "900px",
        "530px"
      );
      commDialog.exec.then((data) => {
        if(data.type == 'ok')
        this.searchLoad();
      });
    },

    /**
     * 成卡申请
     */
    toBatchApply() {
      //页面参数
      var pageParam = {
        loginInfo: this.$util.getLoginer(),
        actType: "add",
      };
      let commDialog = this.$dialog.commDialog(
        "按号段录入申请",
        batchapply,
        pageParam,
        "900px",
        "530px"
      );
      commDialog.exec.then((data) => {
        if(data.type == 'ok')
        this.searchLoad();
      });
    },

    /**
     * 白卡申请
     */
    toApply() {
      //页面参数
      var pageParam = {
        loginInfo: this.$util.getLoginer(),
        actType: "add",
        seleid: "-1",
      };
      let commDialog = this.$dialog.commDialog(
        "联通白卡申请",
        apply,
        pageParam,
        "700px",
        "440px"
      );
      commDialog.exec.then((data) => {
        if(data.type == 'ok')
        this.searchLoad();
      });
    },

    /**
     * 重新申请
     */
    toReApply(row) {
      this.confirmBox = this.$dialog.confirm("确定要提交所选制卡申请记录吗？");
      this.confirmBox.exec.then((btnName) => {
        if (btnName == "ok") {
          this.$util.loadingshow();
          let url = "/herp/cardApplyBatch/" + row.cardApplyBatchId + "/";
          this.$axios
            .post(url, {})
            .then((res) => {
              this.$util.loadinghide();
              let data = res.data;
              if (data.success) {
                this.$dialog.close(this.confirmBox.vm);
                this.dialogVisible = true;
                this.dialog_time = 5;
                this.dialogTimer = setInterval(() => {
                  this.dialog_time--;
                  if (this.dialog_time == 0) {
                    clearInterval(this.dialogTimer);
                    this.dialogVisible = false;
                    this.searchLoad();
                  }
                }, 1000);
              } else {
                this.$dialog.close(this.confirmBox.vm);
                this.$error(data.message);
              }
            })
            .catch((err) => {
              this.$dialog.close(this.confirmBox.vm);
              this.$util.loadinghide();
              console.log(err);
            });
        } else {
          this.$dialog.close(this.confirmBox.vm);
        }
      });
    },

    /**
     * 立即下载并解析
     */
    download2analysNow() {
      this.$axios
        .post("/herp/downloadScheduleFiles/?" + new Date(), {})
        .then((res) => {
          this.$message.success(
            "请求成功，将于后台服务器自动下载所有文件并解析"
          );
        })
        .catch((err) => {
          console.log(err);
        });
    },

    /**
     * 作废申请处理
     */
    toDelDeal(row) {
      this.selectedId = row.cardApplyBatchId;
      //页面参数
      var pageParam = {
        seleid: this.selectedId,
        delApplyBatchNo: row.applyBatchNo,
      };
      let commDialog = this.$dialog.commDialog(
        "作废申请处理",
        deldeal,
        pageParam,
        "700px",
        "400px"
      );
      commDialog.exec.then((resp) => {
        if (resp.type == "ok") {
          this.searchLoad();
        } else if (resp.type == "cancel") {
        }
      });
    },

    /**
     * 可下载文件列表
     */
    toDownloadFileList(row) {
      this.selectedId = row.cardApplyBatchId;
      //页面参数
      var pageParam = {
        seleid: this.selectedId,
      };
      let commDialog = this.$dialog.commDialog(
        "查看可下载文件列表",
        downloadfilelist,
        pageParam,
        "900px",
        "540px"
      );
      commDialog.exec.then((resp) => {
        if (resp.type == "ok") {
        } else if (resp.type == "cancel") {
        }
      });
    },

    /**
     * 查看申请操作日志
     */
    toApplyRecord(row) {
      this.selectedId = row.applyBatchNo;
      //页面参数
      var pageParam = {
        seleid: this.selectedId,
      };
      let commDialog = this.$dialog.commDialog(
        "查看申请操作日志",
        applyrecord,
        pageParam,
        "900px",
        "540px"
      );
      commDialog.exec.then((resp) => {
        if (resp.type == "ok") {
        } else if (resp.type == "cancel") {
        }
      });
    },

    toExportApplyBatch() {
      this.$axios
        .get("/herp/cardApplyBatch/export/", {
          params: this.parampters,
          headers: {
            operator: this.$util.getLoginer().userid,
            withCredentials: true,
          },
        })
        .then((res) => {
          let data = res.data;
          // 关闭提交表单的loading
          if (data.success) {
            let downloadUrl = data.data;
            let n = downloadUrl.split("/");
            var link = document.createElement("a");
            //设置下载的文件名
            link.download = n[n.length - 1];
            link.style.display = "none";
            //设置下载路径
            link.href = downloadUrl;
            //浏览器兼容，禁止打开新的页面
            link.target = "_self";
            //触发点击
            document.body.appendChild(link);
            link.click();
            //移除节点
            document.body.removeChild(link);
          } else {
            this.$error(data.message);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    toMcaDetail(row) {
      this.selectedId = row.applyBatchNo;
      //页面参数
      var pageParam = {
        seleid: this.selectedId,
        actType: "upd",
      };
      let commDialog = this.$dialog.commDialog(
        "新增子任务",
        applybatchupd,
        pageParam,
        "900px",
        "600px"
      );
      commDialog.exec.then((resp) => {
        if (resp.type == "ok") {
        } else if (resp.type == "cancel") {
        }
      });
    },

    toAdd() {
      //页面参数
      var pageParam = {
        seleid: "-1",
        actType: "add",
      };
      let commDialog = this.$dialog.commDialog(
        "新增任务",
        taskdetail,
        pageParam,
        "900px",
        "600px"
      );
      commDialog.exec.then((resp) => {
        if (resp.type == "ok") {
        } else if (resp.type == "cancel") {
        }
      });
    },
    toAddSub(row) {
      var pageParam = {
        seleid: row.cardProduceId,
        actType: "add",
      };
      let commDialog = this.$dialog.commDialog(
        "新增子任务",
        tasksubupd,
        pageParam,
        "900px",
        "600px"
      );
      commDialog.exec.then((resp) => {
        if (resp.type == "ok") {
          this.searchLoad();
        } else if (resp.type == "cancel") {
        }
      });
    },
    toSubDetail(row) {
      var pageParam = {
        seleid: row.cardProduceId,
        actType: "add",
      };
      let commDialog = this.$dialog.commDialog(
        "子任务明细",
        tasksubdetail,
        pageParam,
        "1100px",
        "700px"
      );
      commDialog.exec.then((resp) => {
        if (resp.type == "ok") {
        } else if (resp.type == "cancel") {
        }
      });

      // this.$router.push({
      //   name:'tasksubdetail',
      //   query:{
      //     seleid: row.cardProduceId,
      //     actType: "add"
      //   }
      // })
    },
    //执行/重新执行生产任务
    toRun(row) {
      this.$axios
        .post(`/herp/produce/${row.cardProduceId}/run/`, {
          headers: {
            operator: this.$util.getLoginer().userid,
            withCredentials: true,
          },
        })
        .then((res) => {
          let data = res.data;
          if (data.success) {
            this.$message({
              type: "success",
              message: data.message,
            });
            this.searchLoad();
          } else {
            this.$error(data.message);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //强制执行生产任务
    toForceRun(row) {
      this.$axios
        .post(`/herp/produce/${row.cardProduceId}/forcerun/`, {
          headers: {
            operator: this.$util.getLoginer().userid,
            withCredentials: true,
          },
        })
        .then((res) => {
          let data = res.data;
          if (data.success) {
            this.$message({
              type: "success",
              message: data.message,
            });
            this.searchLoad();
          } else {
            this.$error(data.message);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //生成生产任务结果文件
    toOrganizerunrst(row) {
      this.$axios
        .post(`/herp/produce/${row.cardProduceId}/organizerunrst/`, {
          headers: {
            operator: this.$util.getLoginer().userid,
            withCredentials: true,
          },
        })
        .then((res) => {
          let data = res.data;
          if (data.success) {
            this.$message({
              type: "success",
              message: data.message,
            });
            this.searchLoad();
          } else {
            this.$error(data.message);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    /**
     * 加载任务表格的表头
     */
    loadColumnData(item) {
      this.$axios
        .get(`/herp/table/cardproducerst/column/`, {
          headers: {
            operator: this.$util.getLoginer().userid,
            withCredentials: true,
          },
        })
        .then((res) => {
          let data = res.data;
          // 关闭提交表单的loading
          if (data.success) {
            this.columnData = data.data;
          } else {
            this.$error(data.message);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //加载基础运营商编码
    loadIsp() {
      this.$axios
        .get("/herp/isp/", {
          params: {
            ispName: "",
            pageIndex: this.parampters.pageIndex,
            pageRows: 50,
          },
          headers: {
            operator: this.$util.getLoginer().userid,
            withCredentials: true,
          },
        })
        .then((res) => {
          let data = res.data;
          // 关闭提交表单的loading
          if (data.success) {
            this.ispList = data.data.list;
            console.log(this.ispList);
          } else {
            this.$error(data.message);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //加载虚商列表
    toloadVop() {
      this.$axios
        .get(`/herp/vop/`, {
          params: {
            vopName: "",
            pageIndex: "",
            pageRows: "",
          },
        })
        .then((res) => {
          let data = res.data;
          if (data.success) {
            this.vopList = data.data.list;
          } else {
            this.$error(data.message);
          }
        })
        .catch(function (error) {
          this.fullscreenLoading = false;
        });
    },
    openAnnotation(row, column, cell, event) {
      debugger;
      console.log(row, column, cell, event);
      return (
        <el-tooltip
          class="item"
          effect="dark"
          content={column.label}
          placement="bottom"
        >
          <span>{column.label}</span>
        </el-tooltip>
      );
    },
  },
};
</script>
